//package com.example.administrator.managesystem.activity.my_profile;
//
//import android.app.Activity;
//import android.content.Intent;
//import android.support.v7.widget.GridLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.util.Log;
//import android.view.View;
//import android.widget.TextView;
//
//import com.example.administrator.managesystem.R;
//import com.example.administrator.managesystem.adapter.GridLandAdapter;
//import com.example.administrator.managesystem.base.BaseActivity;
//import com.example.administrator.managesystem.bean.PictureBean;
//import com.example.administrator.managesystem.manager.FullyGridLayoutManager;
//import com.example.administrator.managesystem.utils.ToastUtils;
//import com.example.administrator.managesystem.view.PickLandDialog;
//import com.luck.picture.lib.PictureSelector;
//import com.luck.picture.lib.config.PictureConfig;
//import com.luck.picture.lib.config.PictureMimeType;
//import com.luck.picture.lib.entity.LocalMedia;
//
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * Created by Administrator on 2019/1/5.
// */
//
//public class MyLandActivity extends BaseActivity {
//    private List<PictureBean> pictureList = new ArrayList<>();
//    private List<LocalMedia> selectList = new ArrayList<>();
//    private List<String> land_name = new ArrayList<>();
//
//    private RecyclerView recyclerView;
//    private GridLandAdapter adapter;
//    private int maxSelectNum = 100;
//    private int themeId;
//    private boolean isShow=false;
//    private TextView edit_tv,land_delete;
//    private  PickLandDialog landDialog;
//
//    @Override
//    public void initView() {
//        showfloatButton(true,true);
//        themeId = R.style.picture_default_style;
//        recyclerView = findViewById(R.id.land_recycler);
//        edit_tv=findViewById(R.id.edit_tv);
//        land_delete=findViewById(R.id.land_delete);
//    }
//
//    @Override
//    public void doBusiness() {
//        FullyGridLayoutManager manager = new FullyGridLayoutManager(MyLandActivity.this,3, GridLayoutManager.VERTICAL, false);
//        recyclerView.setLayoutManager(manager);
//        adapter = new GridLandAdapter(MyLandActivity.this, onAddPicClickListener);
//        adapter.setList(pictureList);
//        adapter.setSelectMax(maxSelectNum);
//        recyclerView.setAdapter(adapter);
//        adapter.setOnItemClickListener(new GridLandAdapter.OnItemClickListener() {
//            @Override
//            public void onItemClick(int position, View v) {
//                LocalMedia media = selectList.get(position);
//                String pictureType = media.getPictureType();
//                int mediaType = PictureMimeType.pictureToVideo(pictureType);
//                switch (mediaType) {
//                    case 1:
//                        // 预览图片
//                        PictureSelector.create(MyLandActivity.this).externalPicturePreview(position, selectList);
//                        break;
//                    case 2:
//                        // 预览视频
//                        PictureSelector.create(MyLandActivity.this).externalPictureVideo(media.getPath());
//                        break;
//                    case 3:
//                        // 预览音频
//                        PictureSelector.create(MyLandActivity.this).externalPictureAudio(media.getPath());
//                        break;
//                }
//            }
//        });
//
////          adapter.setOnCheckClickListener(new GridLandAdapter.OnCheckClickListener() {
////              @Override
////              public void onCheckClick(int position, View v) {
////                    Log.e("msg","position:"+position);
////                     selectList.get(position).setChecked(true);
////                  Log.e("msg","size:"+selectList.size());
//////                  LocalMedia media = selectList.get(position);
//////                  media.setChecked(true);
////              }
////          });
//
//          adapter.setOnCheckClickListener(new GridLandAdapter.OnCheckClickListener() {
//              @Override
//              public void onCheckClick(int position, boolean v) {
//                  Log.e("msg","position:"+position);
//                  Log.e("msg","v:"+v);
//                  pictureList.get(position).setChecked(v);
//                  Log.e("msg","size:"+pictureList.size());
//                  Log.e("msg","pictureList.toString():"+pictureList.toString());
//
//              }
//          });
//
//        edit_tv.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//                if(!isShow && !selectList.isEmpty()){
//                    edit_tv.setText("取消");
//                    adapter.setIsVis(true);
//                    isShow=true;
//                    land_delete.setVisibility(View.VISIBLE);
//                }else{
//                    edit_tv.setText("编辑");
//                    adapter.setIsVis(false);
//                    isShow=false;
//                    land_delete.setVisibility(View.GONE);
//                }
//
//                adapter.notifyDataSetChanged();
//            }
//        });
//        land_delete.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//                for (int i = pictureList.size()-1; i >=0; i--) {
//
//                    if (pictureList.get(i).getChecked()) {
//
//                          pictureList.remove(i);
//                          selectList.remove(i);
//                          land_name.remove(i);
//
//                    }
//
//                }
//                adapter.notifyDataSetChanged();
//                adapter.setIsVis(false);
//
//                edit_tv.setText("编辑");
//                land_delete.setVisibility(View.GONE);
//            }
//
//        });
//    }
//
//    @Override
//    public int getLayoutId() {
//        return R.layout.activity_my_land;
//    }
//
//    private GridLandAdapter.onAddPicClickListener onAddPicClickListener = new GridLandAdapter.onAddPicClickListener() {
//        @Override
//        public void onAddPicClick() {
//
//            showDialog();
//
//        }
//    };
//
//    @Override
//    public void onActivityResult(int requestCode, int resultCode, Intent data) {
//        super.onActivityResult(requestCode, resultCode, data);
//        if (resultCode == Activity.RESULT_OK) {
//            switch (requestCode) {
//                case PictureConfig.CHOOSE_REQUEST:
//                    // 图片选择
//                    pictureList.clear();
//                    selectList.addAll(PictureSelector.obtainMultipleResult(data));
//
//                    Log.e("msg","selectList0:"+selectList.size());
//                    for (int i = 0; i < selectList.size(); i++) {
//                        Log.e("msg","selectList1:"+selectList.get(i).getPath());
//                        PictureBean pictureBean=new PictureBean();
//                        pictureBean.setPath(selectList.get(i).getPath());
////                        if(pictureBean.getName() == null || pictureBean.getName().equals("")){
////                            pictureBean.setName(landDialog.getContent());
////                        }
//                        pictureBean.setName(land_name.get(i));
//                        pictureList.add(pictureBean);
//
//                    }
//                    Log.e("msg","selectList.toString:"+pictureList.toString());
//                    adapter.setList(pictureList);
//                    adapter.notifyDataSetChanged();
//                    break;
//            }
//        }
//    }
//    /**
//     * 显示对话框
//     */
//    private void showDialog() {
//        landDialog = new PickLandDialog(MyLandActivity.this);
//
//        landDialog.setOnEnterListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                //如果对话框处于显示状态
//                if (landDialog.isShowing()) {
//                    if(landDialog.getContent().equalsIgnoreCase("")){
//                        ToastUtils.showToast(MyLandActivity.this,"请填写土地名称");
//                        return;
//                    }
//                    landDialog.dismiss();//关闭对话框
//                    land_name.add(landDialog.getContent());
//                    // 进入相册 以下是例子：不需要的api可以不写
//                    PictureSelector.create(MyLandActivity.this)
//                            .openGallery(PictureMimeType.ofAll())
//                            .imageFormat(PictureMimeType.PNG)
//                            .previewImage(true)// 是否可预览图片
//                            .theme(themeId)
//                            .selectionMode(PictureConfig.SINGLE)
//                            .previewVideo(true)
//                            .enablePreviewAudio(true) // 是否可播放音频
//                            .isCamera(true)
//                            .compress(true)
//                            .glideOverride(160, 160)
//                            .minimumCompressSize(100)// 小于 100kb 的图片不压缩
//                            .cropCompressQuality(90)// 裁剪压缩质量 默认100
//                            .selectionMedia(selectList)
//                            .forResult(PictureConfig.CHOOSE_REQUEST);
//
//
//                }
//            }
//        });
//
//
//        //取消
//        landDialog.setOnCancelListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (landDialog != null && landDialog.isShowing()) {
//                    landDialog.dismiss();
//                }
//            }
//        });
//        landDialog.show();
//    }
//
//}
